/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view.GUI.sidepanels;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.AbstractCellEditor;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.TableCellEditor;

/**
 *
 * @author Arfeniel
 */
public class LabelEditor extends AbstractCellEditor
        implements TableCellEditor,
        ActionListener {

    String backup;
    JLabel label;
    EditableTextField textf;

    public LabelEditor() {
        label = new JLabel();
        textf = new EditableTextField("");
        textf.addActionListener(this);
    }

    public void actionPerformed(ActionEvent e) {
        textf = (EditableTextField) e.getSource();
        String input = textf.getText().trim();
        input = input.substring(0, 1).toUpperCase() + input.substring(1);
        label.setText(input);
        fireEditingStopped(); //Make the renderer reappear.
    }

    //Implement the one CellEditor method that AbstractCellEditor doesn't.
    public Object getCellEditorValue() {
        return label;
    }

    //Implement the one method defined by TableCellEditor.
    public Component getTableCellEditorComponent(JTable table,
            Object value,
            boolean isSelected,
            int row,
            int column) {
        label = (JLabel) value;
        backup = label.getText();
        textf.setText(label.getText());
        return textf;
    }
}

